const SERVICE = require("../../lib/js/service.js");
const Golbal = require("../../lib/js/global.js");

Page({
  /*分享*/
  onShareAppMessage(){
    
  },
  
  /*银行卡号*/
  getCardNumber(e){
    let card_number = e.detail.value;
    if (card_number.length > 0 && Golbal.CheckBankNo(card_number) === false){
      wx.showToast({
        title: "请输入正确的银行卡号",
        icon: "none",
        mask: true
      });
    }
  },

  formSubmit(e){
    let form_obj = e.detail.value;
    console.log(form_obj.cardnumber.length);
    if(!form_obj.name){
      wx.showToast({
        title: "请输入姓名",
        icon: "none",
        mask: true
      });
    }else if(!form_obj.cardnumber){
      wx.showToast({
        title: "请输入银行卡号",
        icon: "none",
        mask: true
      });
    } else if (form_obj.cardnumber.length > 0 && Golbal.CheckBankNo(form_obj.cardnumber) === false) {
      wx.showToast({
        title: "请输入正确的银行卡号",
        icon: "none",
        mask: true
      });
    }else if(!form_obj.bandcard){
      wx.showToast({
        title: "请输入银行卡归属银行",
        icon: "none",
        mask: true
      });
    }else{
      SERVICE.POST(SERVICE.URL.bindBankInfo,{
        thirdCookie: wx.getStorageSync("thirdCookie"),
        bankCardNum: form_obj.cardnumber,
        realName: form_obj.name,
        bankName: form_obj.bandcard
      },(status,res)=>{
        console.log(res);
        if(res.data.status === "success"){
          wx.showToast({
            title: "添加成功",
            icon: "none",
            mask: true,
            success: function(){
              wx.navigateBack();
            }
          });
        }else{
          wx.showToast({
            title: res.data.message,
            icon: "none",
            mask: true
          });
        }
      });
    }
  } 
});